home *** CD-ROM | disk | FTP | other *** search
/ PC User 2003 December / Australian PC User - December 2003 (CD2).iso / software / apps / files / dwmx2k4.exe / Disk1 / data1.cab / Configuration_En / DataSources / ColdFusion / Cookie.js < prev    next >
Encoding:
JavaScript  |  2003-09-05  |  5.7 KB  |  231 lines

  1. // Copyright 2001, 2002, 2003 Macromedia, Inc. All rights reserved.
  2.  
  3.  
  4. //************** GLOBALS VARS *****************
  5.  
  6. var COOKIE_FILENAME = "REQ_D.gif";
  7. var DATASOURCELEAF_FILENAME = "DSL_D.gif";
  8.  
  9.  
  10. //****************** API **********************
  11.  
  12. //--------------------------------------------------------------------
  13. // FUNCTION:
  14. //   addDynamicSource
  15. //
  16. // DESCRIPTION:
  17. //   Adds a Dynamic Source to the Data Bindings panel
  18. //
  19. // ARGUMENTS:
  20. //   none
  21. //
  22. // RETURNS:
  23. //   nothing
  24. //--------------------------------------------------------------------
  25.  
  26. function addDynamicSource()
  27. {
  28.   MM.retVal = "";
  29.   MM.CookieContents = "";
  30.   dw.popupCommand("Cookie Variable");
  31.   if (MM.retVal == "OK")
  32.   {
  33.     var theResponse = MM.CookieContents;
  34.     if (theResponse.length)
  35.     {
  36.       var siteURL = dw.getSiteRoot();
  37.       if (siteURL.length)
  38.       {
  39.         dwscripts.addListValueToNote(siteURL, "Cookie", theResponse);   
  40.       }
  41.       else
  42.       {
  43.         alert(MM.MSG_DefineSite);
  44.       }
  45.     }
  46.     else 
  47.     {
  48.       alert(MM.MSG_DefineCookie);
  49.     }
  50.   }
  51. }
  52.  
  53.  
  54. //--------------------------------------------------------------------
  55. // FUNCTION:
  56. //   findDynamicSources
  57. //
  58. // DESCRIPTION:
  59. //   Returns a list of Dynamic Sources on the page
  60. //
  61. // ARGUMENTS:
  62. //   none
  63. //
  64. // RETURNS:
  65. //   JavaScript Array of Objects
  66. //--------------------------------------------------------------------
  67.  
  68. function findDynamicSources()
  69. {
  70.   var retList = new Array();
  71.  
  72.   var siteURL = dw.getSiteRoot()
  73.  
  74.   if (siteURL.length)
  75.   {
  76.     var bindingsArray = dwscripts.getListValuesFromNote(siteURL, "Cookie");
  77.     if (bindingsArray.length > 0)
  78.     {
  79.       retList.push(new DataSource(MM.LABEL_Cookie, 
  80.                                   COOKIE_FILENAME, 
  81.                                   false, 
  82.                                   "Cookie.htm"))
  83.     }
  84.   }
  85.  
  86.   return retList;
  87. }
  88.  
  89.  
  90. //--------------------------------------------------------------------
  91. // FUNCTION:
  92. //   generateDynamicSourceBindings
  93. //
  94. // DESCRIPTION:
  95. //   Returns a list of bindings for the given elementName on the page.
  96. //
  97. // ARGUMENTS:
  98. //   sourceName - string - the name returned from the findDynamicSources
  99. //     function
  100. //
  101. // RETURNS:
  102. //   JavaScript Array of Objects
  103. //--------------------------------------------------------------------
  104.  
  105. function generateDynamicSourceBindings(sourceName)
  106. {
  107.   var retVal = new Array();
  108.  
  109.   var siteURL = dw.getSiteRoot();
  110.  
  111.   //For localized object name
  112.   if (sourceName != "Cookie")
  113.   {
  114.     sourceName = "Cookie";
  115.   }
  116.  
  117.   if (siteURL.length)
  118.   {
  119.     var bindingsArray = dwscripts.getListValuesFromNote(siteURL, sourceName);
  120.     retVal = getDataSourceBindingList(bindingsArray, 
  121.                                       DATASOURCELEAF_FILENAME,
  122.                                       true,
  123.                                       "Cookie.htm");
  124.   }
  125.  
  126.   return retVal;
  127. }
  128.  
  129.  
  130. //--------------------------------------------------------------------
  131. // FUNCTION:
  132. //   generateDynamicDataRef
  133. //
  134. // DESCRIPTION:
  135. //   Returns a dynamic binding string.
  136. //
  137. // ARGUMENTS:
  138. //   sourceName - string - the name of the dynamic source returned
  139. //     from the findDynamicSources function
  140. //   bindingName - string - the name of a dynamic source binding returned
  141. //     from generateDynamicSourceBindings
  142. //
  143. // RETURNS:
  144. //   string - the code to insert on the page
  145. //--------------------------------------------------------------------
  146.  
  147. function generateDynamicDataRef(sourceName, bindingName, dropObject)
  148. {
  149.   var paramObj = new Object();
  150.   paramObj.bindingName = bindingName;
  151.   var retStr = extPart.getInsertString("", "Cookie_DataRef", paramObj);
  152.  
  153.   // We need to strip the cfoutput tags if we are inserting into a CFOUTPUT tag
  154.   // or binding to the attributes of a ColdFusion tag.
  155.   if (dwscripts.canStripCfOutputTags(dropObject, true))
  156.   {
  157.     retStr = dwscripts.stripCFOutputTags(retStr, true);
  158.   } 
  159.  
  160.   return retStr;
  161. }
  162.  
  163.  
  164. //--------------------------------------------------------------------
  165. // FUNCTION:
  166. //   inspectDynamicDataRef
  167. //
  168. // DESCRIPTION:
  169. //   Inspects a dynamic binding string and returns a pair of 
  170. //   source and binding values.
  171. //
  172. // ARGUMENTS:
  173. //   expression - string - the dynamic binding expression to be
  174. //     inspected
  175. //
  176. // RETURNS:
  177. //   JavaScript Array of strings - an array of length 2, with the first
  178. //   value being the sourceName, and the second being the bindingName
  179. //--------------------------------------------------------------------
  180.  
  181. function inspectDynamicDataRef(expression)
  182. {
  183.   var retArray = new Array();
  184.  
  185.   if(expression.length)
  186.   {
  187.     var params = extPart.findInString("Cookie_DataRef", expression);
  188.     if (params)
  189.     {
  190.       retArray[0] = params.sourceName;
  191.       retArray[1] = params.bindingName;
  192.     }
  193.   }
  194.     
  195.   return retArray;
  196. }
  197.  
  198.  
  199. //--------------------------------------------------------------------
  200. // FUNCTION:
  201. //   deleteDynamicSource
  202. //
  203. // DESCRIPTION:
  204. //   Deletes a dynamic source from the document.
  205. //
  206. // ARGUMENTS:
  207. //   sourceName - string - the name of the dynamic source returned
  208. //     from the findDynamicSources function
  209. //   bindingName - string - the name of a dynamic source binding returned
  210. //     from generateDynamicSourceBindings
  211. //
  212. // RETURNS:
  213. //   nothing
  214. //--------------------------------------------------------------------
  215.  
  216. function deleteDynamicSource(sourceName, bindingName)
  217. {
  218.   var siteURL = dw.getSiteRoot();
  219.       
  220.   if (siteURL.length)
  221.   {
  222.     //For localized object name
  223.     if (sourceName != "Cookie")
  224.     {
  225.       sourceName = "Cookie";
  226.     }
  227.  
  228.     dwscripts.deleteListValueFromNote(siteURL, sourceName, bindingName);
  229.   }
  230. }
  231.